﻿@page "/_Major/Major/Create"
@using WBBvNext.ViewModel._Major.MajorVMs;
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.FormRow">

            <BootstrapInput @bind-Value="@Model.Entity.MajorCode"  />
            <BootstrapInput @bind-Value="@Model.Entity.MajorName"  />
            <BootstrapInput @bind-Value="@Model.Entity.Remark"  />
            <Select @bind-Value="@Model.Entity.SchoolId" Items="@AllSchools" PlaceHolder="@WtmBlazor.Localizer["Sys.PleaseSelect"]"/>
    <Row ColSpan="2">
            <Transfer @bind-Value="@Model.SelectedStudentMajorsIDs" Items="@AllStudents" />
    </Row>
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose" />
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Create"]" IsAsync="true" />
    </div>
</ValidateForm>

@code {

    private MajorVM Model = new MajorVM();
    private ValidateForm vform { get; set; }

    private List<SelectedItem> AllSchools = new List<SelectedItem>();

    private List<SelectedItem> AllStudents = new List<SelectedItem>();


    protected override async Task OnInitializedAsync()
    {

        AllSchools = await WtmBlazor.Api.CallItemsApi("/api/Major/GetSchools", placeholder: WtmBlazor.Localizer["Sys.PleaseSelect"]);

        AllStudents = await WtmBlazor.Api.CallItemsApi("/api/Major/GetStudents");

        await base.OnInitializedAsync();
    }


    private async Task Submit(EditContext context)
    {
        await PostsForm(vform, "/api/Major/add", (s) => "Sys.OprationSuccess");
    }

    public void OnClose()
    {
        CloseDialog();
    }

}
